<?php
if ($this->userland->logged_in()):
	$user = $this->userland->current_user();
	
	$yours = $this->db->query('select * from bricaboxes where user_id = ?', array($user->id));
	$membr = $this->db->query('select * from bricaboxes where id in (select bricabox_id from memberships where user_id = ? and role_id < 5)', array($user->id)); // not owner
	$by	   = array();
	$bm	   = array();
?>
<div id="user_panel" style="display: none;">
	<div id="user_panel_inner">
		<h1><img src="<?php echo url_for_avatar($user->avatar, $user->id, 'user', 'medium'); ?>" alt="Your avatar" width="50" height="50" />
			<?php echo username($user); ?></h1>
		<p><a href="<?php echo APP_ROOT_URL; ?>/person/<?php echo user_url($user); ?>">View your global profile</a>
		| <a href="/account/edit">Edit your account</a>
		| <a href="/log_out">Log out</a></p>
		<p>Your BricaBoxes: <?php foreach ($yours->result() as $b): $by[] = "<a href=\"".bricabox_url($b)."\">{$b->name}</a>"; endforeach; echo join(', ', $by); ?></p>
		<p>BricaBoxes you're a member of: <?php foreach ($membr->result() as $b): $bm[] = "<a href=\"".bricabox_url($b)."\">{$b->name}</a>"; endforeach; echo join(', ', $bm); ?></p>
	</div>
	<a href="#" onclick="return Userpanel.hide();" class="close" title="Close"><img src="/assets/images/close.png" alt="Close" /></a>
</div>
<?php endif; ?>